<template>
  <basic-container>
    <avue-crud
      :data="data"
      :option="option"
      :page.sync="page"
      @on-load="rowLoad"
      @search-change="searchChange"
      @row-update="rowUpdate"
      @row-del="rowDel"
      @row-save="rowSave"
      @size-change="sizeChange"
      @current-change="currentChange"
    >
    </avue-crud>
  </basic-container>
</template>

<script>
import avue from "@/mixins/avue.js";
import {
  ossChannel_page,
  ossChannel_edit,
  ossChannel_delete,
  ossChannel_add,
} from "@/api/core/system";

export default {
  mixins: [avue],
  data() {
    return {
      data: [],
      option: {
        dialogWidth: "30%",
        span: 24,
        column: [
          {
            label: "名称",
            prop: "name",
            search: true,
          },
          {
            label: "编码",
            prop: "code",
          },
          {
            label: "备注",
            prop: "remark",
          },
          {
            label: "配置",
            prop: "config",
            type: "textarea",
            span: 24,
            minRows: 5,
          },
          {
            label: "状态",
            prop: "status",
            type: "radio",
            value: 1,
            dicData: [
              {
                label: "启用",
                value: 1,
              },
              {
                label: "停用",
                value: 0,
              },
            ],
          },
        ],
      },
    };
  },
  created() {},
  methods: {
    rowLoad() {
      ossChannel_page(this.params).then((res) => {
        this.data = this.$s.res(res).records;
      });
    },
    rowSave(row, loading, done) {
      ossChannel_add(row)
        .then((res) => {
          this.$s.suc(res);
        })
        .then(() => {
          this.rowLoad();
          done();
          loading();
        });
    },
    rowUpdate(row, index, done, loading) {
      ossChannel_edit(row)
        .then((res) => {
          this.$s.suc(res);
        })
        .then(() => {
          this.rowLoad();
          done();
          loading();
        });
    },
    rowDel(row, loading, done) {
      this.$confirm("确定数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        ossChannel_delete({ ids: row.id })
          .then((res) => {
            this.$s.suc(res);
          })
          .then(() => {
            this.rowLoad();
            done();
            loading();
          });
      });
    },
  },
  mounted() {},
};
</script>

<style lang="scss" scoped></style>
